package ms.unicorn.modellanguage;

import ms.unicorn.diagram.providers.UnicornElementTypes;
import ms.unicorn.util.ConfigUtil;
import ms.unicorn.util.TypeConvert;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;

public class LanguageEntity extends LanguageElement {

	private LanguageEntityEditHeperAdvice advice;
	private boolean resizeable;
	private int figureType;
	private Dimension defaultSize;

	public LanguageEntity(IModelLanguage language) {
		super(language);
	}
	
	public LanguageEntity(IModelLanguage language, IConfigurationElement config) {
		super(language, config);
	}
	
	@Override
	protected void load(IConfigurationElement config) {
		super.load(config);
		resizeable = ConfigUtil.getBoolean(config, "resizeable", true);
		figureType = TypeConvert.toFigureConstant(ConfigUtil.get(config, "figure", "default"));
		defaultSize = new Dimension(
					ConfigUtil.getInt(config, "width", 40),
					ConfigUtil.getInt(config, "height", 40)
				);
	}
	
	@Override
	protected IElementType getBaseType() {
		return UnicornElementTypes.Entity_2001;
	}
	
	public boolean acceptChild(LanguageElement element) {
		return advice.acceptChildren(element);
	}
	
	public void setEditHelperAdvice(IElementEditHelperAdvice advice) {
		this.advice = (LanguageEntityEditHeperAdvice)
			(advice instanceof LanguageEntityEditHeperAdvice ? advice : null);
	}

	@Override
	public LanguageEntityEditHeperAdvice getEditHelperAdvice() {
		return advice != null ? advice : LanguageEntityEditHeperAdvice.DefaultInstance;
	}

	public void setResizeable(boolean resizeable) {
		this.resizeable = resizeable;
	}

	public boolean isResizeable() {
		return resizeable;
	}

	public void setFigureType(int figure) {
		this.figureType = figure;
	}

	public int getFigureType() {
		return figureType;
	}

	public void setDefaultSize(Dimension defaultSize) {
		this.defaultSize = defaultSize;
	}

	public Dimension getDefaultSize() {
		return defaultSize;
	}
}
